unit Funcoes;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TFuncoes = class(TComponent)
  private
    function WindowsVer: string;
    function TotalMemoria: string;
   { Private declarations }
  protected
   { Protected declarations }
  public
    function VersaoArquivo(FName, InfoType: string): string;
    { Public declarations }
  published
    property VersaoDoWindows: string read WindowsVer;
    property MemoriaTotal: string read TotalMemoria;
    { Published declarations }
  end;


procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Standard', [TFuncoes]);
end;

function TFuncoes.WindowsVer: string;
var
  OSVersionInfo: TOSVersionInfo;
begin
  OsVersionInfo.dwOSVersionInfoSize := SizeOf(TOsVersionInfo);
  GetVersionEx(OsVersionInfo);
  with OsVersionInfo do begin
      case dwPlatformID of
        VER_PLATFORM_WIN32S: result := 'Win32s';
        VER_PLATFORM_WIN32_WINDOWS: result := 'Windows 95/98/Me';
        VER_PLATFORM_WIN32_NT: result := 'Windows XP';
      else
        result := 'Windows 3.X';
      end;
    end;
end;

function TFuncoes.TotalMemoria: string;
var
  MS: TMemoryStatus;
begin
  MS.dwLength := SizeOf(TMemoryStatus);
  GlobalMemoryStatus(MS);
  result := FormatFloat('#,###" KB"', MS.dwTotalPhys div 1024);
end;

function TFuncoes.VersaoArquivo(FName, InfoType: string): string;
var Info: Pointer;
  InfoData: Pointer;
  InfoSize: LongInt;
  InfoLen: {$IFDEF WIN32}DWORD; {$ELSE}LongInt; {$ENDIF}
  DataLen: {$IFDEF WIN32}UInt; {$ELSE}Word; {$ENDIF}
  LangPtr: Pointer;
begin
  Result := '';
  DataLen := 255;
  if Length(FName) <= 0 then
    exit;
  FName := FName + #0;
  InfoSize := GetFileVersionInfoSize(@Fname[1], InfoLen);
  if (InfoSize > 0) then begin
      GetMem(Info, InfoSize);
      try
        if GetFileVersionInfo(@FName[1], InfoLen, InfoSize, Info) then begin
            if VerQueryValue(Info, '\VarFileInfo\Translation', LangPtr, DataLen) then
              InfoType := Format('\StringFileInfo\%0.4x%0.4x\%s'#0,
                [LoWord(LongInt(LangPtr^)), HiWord(LongInt(LangPtr^)), InfoType]);
            if VerQueryValue(Info, @InfoType[1], InfoData, Datalen) then
              Result := strPas(InfoData);
          end;
      finally
        FreeMem(Info, InfoSize);
      end;
    end;
end;
end.

